import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', 8000))

ab = {}

while True:
	data, address = sock.recvfrom(8192)
	print 'data', repr(data)
	if data[0] == '\x01':
		print "receive from server: ", address
		print "ID:", ord(data[1])
		print "CMD:", data[2:]
		sock.sendto(data[2:],ab[data[1]])
	if data[0] == '\x02':
		print "receive from client: ", address
		print "ID:", ord(data[1])
		ab[data[1]] = address
	#for ID, add in ab.items():
	#	print repr(ID),add
sock.close()
